<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@include file="../connection.jsp"%>
<%

  //HttpSession session = request.getSession();
  //session = request.getSession();
  
  String userid = (String)session.getAttribute("admin");
  
  if(userid==null)
  {
  	response.sendRedirect("../login.jsp");
  }  
   
   String oldPass = request.getParameter("old_password");
   String message="";
   
   if(oldPass!=null){
     Connection c = getAdminConnection();	
	 Statement s = c.createStatement();    
   	   ResultSet rs = s.executeQuery("select password from users where userid='"+userid+"'");
   	   if(rs.first()){
   	   		if(rs.getString(1).equals(oldPass)){
   	   			s.executeUpdate("update users set password='"+request.getParameter("new_password")+"' where userid='"+userid+"'");
   	   			message = "Password changed successfully.";
   	   		}else{
   	   			message = "Invalid password.";
   	   		}
   	   }
           rs.close();
           c.close();
           s.close();
   }
   
   
  %>
<html>
<head>
<link href="../css/medbill.css" rel="stylesheet" type="text/css" />
<title>PMS Home</title>
<script language="javascript">
function validateForm(){
	
	var oldPass = document.getElementById("old_password");
	var newPass = document.getElementById("new_password");
	var confirmPass = document.getElementById("confirm_password");
	
	if(oldPass.value.length==0)
	{
		alert("Please enter old password");
		oldPass.focus();		
		return false;
	}else if(newPass.value.length > 0)
	{
	
		if(newPass.value!=confirmPass.value){
			alert("Confirm password does not match.");
			confirmPass.focus();
			return false;
		}
	}else{
			alert("Enter new password.");
			newPass.focus();
			return false;
	}
	
	return true;
	
}
</script>
</head>
<body>
<table width="860" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="204" valign="top"><%@include file="header.jsp"%></td>
  </tr>
  <tr>
    <td height="30" bgcolor="#1f226f" class="headingBlue">Medical Billing and Claim Processing Professionals</td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#ccae74"><table width="96%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="470" valign="top" class="txtPageTitle">Change Password</td>
            <td>&nbsp;</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="560"></td>
              </tr>
              <tr>
                <td class="txtHomeBody"></td>
              </tr>
            </table>
              <br>
<form name="ChangePassword" onsubmit="return validateForm();" action="change_password.jsp" method="post">
  <div>
  <table border="0" width="400" cellpadding="0">
  <tr>
		<td width="394" colspan="2"><font color='red'><%=message%></font></td>
	</tr>
	<tr>
		<td width="120" align="left">Old Password:</td>
		<td width="274">
    <input type="password" name="old_password" id="old_password" size="20" /></td>
	</tr>
	<tr>
		<td width="120" align="left">New Password:</td>
		<td width="274">
    <input type="password" name="new_password" id="new_password" size="20" /></td>
	</tr>
	<tr>
		<td width="120" align="left">Confirm Password:</td>
		<td width="274">
    <input type="password" name="confirm_password" id="confirm_password" size="20" /></td>
	</tr>
	<tr>
		<td width="120">&nbsp;</td>
		<td width="274">&nbsp;</td>
	</tr>
	<tr>
		<td width="120">&nbsp;</td>
		<td width="274"><input type="submit" value="Change"/> 
		<input type="button" value="Cancel" onclick="location='home.jsp';"/></td>
	</tr>
	</table>
  </div>
</form><br />
<br />
<br />
<br />
<br /><br />
<br />

			  </td>
            <td width="45" valign="top">&nbsp;</td>
            <td valign="top">&nbsp;</td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="62" valign="top"><!-- #BeginLibraryItem "/Library/footer.lbi" --><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="4" bgcolor="#c7540f"></td>
      </tr>
      <tr>
        <td height="58" bgcolor="#1e2667">&nbsp;</td>
      </tr>
    </table><!-- #EndLibraryItem --></td>
  </tr>
</table>
</body>
</html>
